if SERVER then

	/* First player spawn */
	local function PlayerInitialSpawn( ply )
	
		/* Find all maps */
		for i, mapName in ipairs( file.Find( "../maps/*" ) ) do
			
			if string.match( mapName, "(%.bsp)$" ) then

				/* Debug */
				Msg( "Sending map name " .. mapName .. "\n" )
				
				/* Play a sound */
				ply:EmitSound("ambient/energy/zap1.wav", 500, 200)
				
				/* Send a message for each map name */
				umsg.Start( "AddMap", ply )
				umsg.String( mapName )
				umsg.End()
			end
		end
	end
	
	/* Add a hook to PlayerInitialSpawn */
	hook.Add( "PlayerInitialSpawn", "SendMapList", PlayerInitialSpawn )
end

/*************************************************************************/

if CLIENT then

	/* Maps table */
	local MapList = {}
	
	/* Callback - Store map name */
	local function AddMap( data )
	
		/* Read the map name */
		local mapName = data:ReadString()
		
		/* Insert the received map name into the maps table */
		table.insert( MapList, mapName )
		
		/* Output it in player's chat */
		chat.AddText(
			Color(60, 224, 27),
			"Map received: ",
			Color(27, 178, 224),
			mapName)
			
		/* Debug */
		Msg( "Map received: " .. mapName .. "\n" )
	end
	
	/* Add a hook for AddMap */
	usermessage.Hook( "AddMap", AddMap )
end